package gui;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

/**
 * @author dotekien
 *         Date: Apr 11, 2006
 *         Time: 6:41:24 PM
 */
public class SameTableMouseListener extends MouseAdapter {
    JComboBox combo;

    public SameTableMouseListener(JComboBox combo) {
        this.combo = combo;
    }

    public void mouseClicked(MouseEvent e) {
        Object ob = e.getSource();
        if (ob instanceof JTable) {
            JTable table = (JTable) ob;
            Point p = e.getPoint();
            int row = table.rowAtPoint(p);
            //set list[row] in combox become active
            Integer id = (Integer) table.getValueAt(row, 0);
            if (combo.getSelectedIndex() > -1) {
                combo.setSelectedIndex(id);
            }
            //System.out.println(combo.getSelectedIndex());
        }
    }
}
